package com.gwd.task.model;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.gwd.task.entity.ProductionEventsEntity;
import com.gwd.task.group.GroupInsert;
import com.gwd.task.group.GroupUpdate;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhiyongming
 * @date 2020/12/2 18:02
 */
@Data
@NoArgsConstructor
public class ProductionEventsDTO {
    @NotNull(groups = {GroupUpdate.class})
    private Long peId;
    private String peCode;
    //所属小组
    @NotNull(groups = {GroupInsert.class, GroupUpdate.class})
    private Integer group;
    //项目id
    @NotNull(groups = {GroupInsert.class, GroupUpdate.class})
    private Long projectId;
    //项目id
    private String projectName;
    //模块id
    private Long[] moduleId;
    private Long lv1ModuleId;
    private Long lv2ModuleId;
    //任务
    private Long taskId;
    //模块
    private String lv1ModuleName;
    private String lv2ModuleName;
    //责任人
    @NotNull(groups = {GroupInsert.class, GroupUpdate.class})
    private Long respPerson;
    private String respPersonName;
    //开发负责人
    @NotNull(groups = {GroupInsert.class, GroupUpdate.class})
    private Long devPerson;
    private String devPersonName;
    //测试负责人
    @NotNull(groups = {GroupInsert.class, GroupUpdate.class})
    private Long testPerson;
    private String testPersonName;
    //事件状态
    private Integer peStatus;
    //开发状态
    private Integer devStatus;
    //事件类型
    @NotNull(groups = {GroupInsert.class, GroupUpdate.class})
    private Integer peType;
    //事件详细描述
    @NotBlank(groups = {GroupInsert.class, GroupUpdate.class})
    private String describe;
    //记录时间
    private Date record;
    private String recordBegin;
    private String recordEnd;
    //预计修复时间
    private Date preRepair;
    //计划投产时间
    private Date preOnline;
    //是否需要跟踪
    private Integer needFollow;
    //备注
    private String remarks;
    //创建人
    private Long createUser;
    //创建时间
    private Date createTime;
    //临时编号
    private String tempCode;

    private List<AttachmentDTO> attachments;
    private List<EventsProcessDTO> process;

    public void addAttachment(AttachmentDTO dto) {
        if (this.attachments==null) {
            this.attachments = new ArrayList<>();
        }
        this.attachments.add(dto);
    }

    public void addProcess(EventsProcessDTO dto) {
        if (this.process==null) {
            this.process = new ArrayList<>();
        }
        this.process.add(dto);
    }

    public ProductionEventsDTO(ProductionEventsEntity entity) {
        BeanUtil.copyProperties(entity, this, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(false));
    }

    public String getPeStatusName() {
        switch (this.peStatus) {
            case 0:
                return "待解决";
            case 1:
                return "已解决";
            case 2:
                return "关闭";
        }
        return "";
    }

    public String getDevStatusName() {
        switch (this.devStatus) {
            case 0:
                return "待确认";
            case 1:
                return "已分配";
            case 2:
                return "已提交";
            case 3:
                return "待测试";
            case 4:
                return "已完成";
            case 5:
                return "关闭";
        }
        return "";
    }
}
